package com.jilin.library.service;

import com.jilin.library.entity.PurchaseRecord;
import com.jilin.library.mapper.PurchaseRecordMapper;
import com.jilin.library.mapper.BookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
public class PurchaseRecordService {
    @Autowired
    private PurchaseRecordMapper purchaseRecordMapper;
    
    @Autowired
    private BookMapper bookMapper;
    
    public List<PurchaseRecord> findAll() {
        return purchaseRecordMapper.findAll();
    }
    
    @Transactional
    public PurchaseRecord addPurchase(PurchaseRecord record) {
        // 增加图书库存
        bookMapper.updateStock(record.getBookId(), record.getQuantity());
        purchaseRecordMapper.insert(record);
        return record;
    }
} 